package com.tcwlkj.uuService.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tcwlkj.uuService.R;
import com.tcwlkj.uuService.model.ShareModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/27 0027.
 */

public class RecommentAdapter extends RecyclerView.Adapter<RecommentAdapter.ViewHolder>{
    private List<ShareModel.Details> mMsgList;

    public RecommentAdapter(List<ShareModel.Details> mMsgList) {
        this.mMsgList = mMsgList;
    }

    public void updateData(List<ShareModel.Details> data) {
        this.mMsgList = data;
        notifyDataSetChanged();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder viewHolder=new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recomment,parent,false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String phone=mMsgList.get(position).getRUMobile();
        StringBuilder sb = new StringBuilder(phone);
        sb.replace(3, 7, "****");
        sb.substring(7, 11);
        holder.tv_phone.setText(sb.toString());
        String str=mMsgList.get(position).getURItems();
        String[] strs=str.split(",");
        String s="";
        for(int i=0,len=strs.length;i<len;i++){
            if(mMsgList.get(position).getRURItems().indexOf(strs[i])==-1){
                s =s+strs[i]+",";
            }
        }
        if(s.equals("")){
            s="无";
        }
        holder.tv_no.setText(s);
        holder.tv_yes.setText(mMsgList.get(position).getRURItems());
        holder.tv_money.setText(mMsgList.get(position).getRURValue());

    }

    @Override
    public int getItemCount() {
        return mMsgList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_phone;
        TextView tv_no;
        TextView tv_yes;
        TextView tv_money;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_phone= (TextView) itemView.findViewById(R.id.tv_phone);
            tv_no= (TextView) itemView.findViewById(R.id.tv_no);
            tv_yes= (TextView) itemView.findViewById(R.id.tv_yes);
            tv_money= (TextView) itemView.findViewById(R.id.tv_money);
        }
    }
}
